<template>
    <div class="container"  >
        <div class="main">
            <div class="head">支付中心</div>
            
            <div class="content code" v-loading="loading">
                <div class="con" v-if="orderInfo.orderState==1">
                    <img class="img" :src="PIC_URL+'/images/gm_cg.png'" width="338" height="290">
                    <div class="title">支付成功</div>
                    <div class="item"><span class="tip">产品名称:</span> <span class="name">{{ poductDetail.productName || '' }}</span></div>
                    <div class="item"><span class="tip">支付价格:</span> <span class="price">￥{{ poductDetail.actPrice | totalMoney }}</span></div>
                    <div class="item"><span class="tip">支付时间:</span> <span class="time">{{new Date() | formatDate('YYYY-MM-DD')}}</span></div>
                </div>
                <div class="con" v-else>
                    <img class="img" :src="PIC_URL+'/images/gm_shi_bai1.png'" width="338" height="290">
                    <div class="title">支付失败</div>
                    <div class="rePay" @click="goPay"><span>重新支付</span></div>
                </div>
                
            </div>
        </div>

        
    </div>
</template>

<script>
import {getProductDetail,getOrderDetail} from '../api'
import {getUrlParams} from '@/common/common';
const {productId} = getUrlParams();
export default {
    name: "Home",
    data() {
        return {
            productId:productId||79,
            poductDetail:{},
            orderInfo:{},
            loading: true
        }
    },
    created(){
        this.getProductDetail();
        this.loading = true;
        setTimeout(() => {
            this.getOrderDetail();
        }, 2000);
        
    },
    filters:{
        totalMoney(num){
            if(num <= 0 || !num){
                return 0;
            }else{
                return num.toFixed(2);
            }
        }
    },
    methods: {
        //产品信息
        getProductDetail() {
            // let productId = this.payFlag.productId || '';
            getProductDetail(this.productId).then(res => {
                this.poductDetail = res.data[0];
            });
        },
        // 获取订单信息
        getOrderDetail(){
            // 只管 1 是已支付 其他不管
            // 0未支付 1已完成 2已取消 3申请退款 4退款成功 5订单关闭 6 服务中 7待确认 8试用期 9试用到期
            let orderNum = localStorage.getItem('orderNum');
            getOrderDetail(orderNum).then(res => {
                this.orderInfo = res.data || {};
                this.loading = false;
            }).catch(err=>{
                this.loading = false;
            })
        },
        goPay(){
            window.location.href = `${window.location.origin}/webclient/simplePay/index.html#/`
        }
    }
}
</script>

<style lang="scss">
html, body {
    background: #F7F8FA;
}
</style>

<style scoped lang="scss">
.container{
   width: 100%;
   border-top:1px solid #fff;
    .main{
        width: 1000px;
        margin: auto;
        background: #fff;
        margin-top: 60px;
        box-sizing: border-box;
        .head{
            color: #fff;
            font-size: 24px;
            padding: 24px 150px;
            box-sizing: border-box;
            background: url($PIC_URL + '/images/tittle_bg.png') no-repeat 100%;
        }
        .content{
            &.code {
                .con{
                    color: #333;
                    display: flex;
                    flex-direction: column;
                    align-items: center;
                    .img{
                        margin-top: 87px;
                    }
                    .title{
                        margin: 40px 0;
                        font-size: 24px;
                        text-align: center;
                        font-weight: bold;
                    }
                    .item {
                        width: 270px;
                        display: inline-block;
                        display: flex;
                        align-items: center;
                        &:nth-child(3){
                            margin-bottom: 23px;
                        }
                        &:nth-child(4){
                            margin-bottom: 25px;
                        }
                        &:nth-child(5){
                            margin-bottom: 150px;
                        }
                        .tip{
                            padding-right: 30px;
                        }
                        .price{
                            color: #F01414;
                            font-size: 24px;
                        }
                        
                    }
                    .rePay{
                        text-align: center;
                        margin-top: -16px;
                        span {
                            display: inline-block;
                            font-size: 17px;
                            font-weight: 500;
                            color: #FFFFFF;
                            border-radius: 2px;
                            background: #EA2827;
                            padding: 12px 42px;
                            cursor: pointer;
                            font-family: Microsoft YaHei;
                        }
                        margin-bottom: 364px;
                    }
                }
            }
        }
    }
}

</style>